using Microsoft.AspNetCore.Mvc;
using PowerManage.API.AuditLog;
using PowerManage.API.Auth;
using PowerManage.Entity;
using PowerManage.Entity.Dtos.AudiLogs;
using PowerManage.Service;

namespace PowerManage.API.Controllers;

/// <summary>
/// 审核日志
/// </summary>
[Route("api/[controller]")] //用户指定路由前缀 api/auditLogs
[PermissionAuthorize]
[AuditLog(false)] // 关闭审核日志记录，避免无限循环
public class AuditLogsController : BaseController
{
    private IAuditLogService _auditLogService;

    /// <summary>
    /// 构造器注入
    /// </summary>
    /// <param name="auditLogService"></param>
    public AuditLogsController(IAuditLogService auditLogService)
    {
        _auditLogService = auditLogService;
    }

    /// <summary>
    /// 根据条件分页获取审核日志列表
    /// </summary>
    /// <param name="audiLogPageRequestDto"></param>
    /// <returns></returns>
    [HttpGet]
    public IActionResult Get([FromQuery] AudiLogPageRequestDto audiLogPageRequestDto)
    {
        // 获取审核日志
        var auditLogPageResponseDto = _auditLogService.Query(audiLogPageRequestDto);
        return Ok(auditLogPageResponseDto);
    }

    /// <summary>
    /// 删除审核日志
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete("{id}")]
    [AuditLog(true)]
    public IActionResult Delete(long id)
    {
        // 删除审核日志
        bool success = _auditLogService.Delete(id);
        if (success)
        {
            return NoContent();
        }
        else
        {
            return BadRequest(new ResponseResultDto().SetError("删除审核日志失败"));
        }
    }
}